define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'cardlist/index',
                    add_url: 'cardlist/add',
                    edit_url: 'cardlist/edit',
                    del_url: 'cardlist/del',
                    multi_url: 'cardlist/multi',
                    table: 'card_list',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search: false,
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'merid', title: __('Merid')},
                        {field: 'no', title: __('No'), operate:'BETWEEN'},
                        {field: 'password', title: __('Password')},
                        {field: 'amount', title: __('Amount'), operate:'BETWEEN'},
                        {field: 'expiration_time', title: __('Expiration_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'days', title: __('Days')},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), visible:false, searchList: Config.statusList},
                        {field: 'status_text', title: __('Status'), operate:false},
                        {field: 'user.username', title: __('User_id')},
                        {field: 'use_time', title: __('Use_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'type', title: __('Type'), visible:false, searchList: Config.typeList},
                        {field: 'type_text', title: __('Type'), operate:false},
                        {field: 'batch_no', title: __('Batch_no')},
                        {field: 'agent.mobile', title: __('归属代理')},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
            $(document).on('click', '.btn-agent', function () {
                console.log('aaa');
                
                Fast.api.open('cardlist/agent', __('批量划卡'), $(this).data() || {});
            })
            
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        agent: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));

                
            }
        }
    };
    return Controller;
});